from enum import IntEnum
from typing import List
from collections import OrderedDict

GAME_STATE_N = {
    "PREFLOP":0,
    "FLOP":1,
    "TURN":2,
    "RIVER":3
}

class ACTION(IntEnum):
    FOLD = 0
    CHECK = 1
    CALL = 2
    RAISE_HALF_POT = 3
    RAISE_FULL_POT = 4
    ALL_IN = 5

class CARD_TYPE(IntEnum):
    ROYAL_STRAIGHT = 0
    FLUSH_STRAIGHT = 1
    FOUR = 2
    FULL_HOUSE = 3
    FLUSH = 4
    STRAIGHT = 5
    THREE = 6
    TWO_PAIR = 7
    PAIR = 8
    SINGLE = 9


COLOR = ['S', 'H', 'D', 'C']
NUMBER = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']

# 牌型数量
SCORE_DIST = OrderedDict(
    {
        # 皇家同花
        CARD_TYPE.ROYAL_STRAIGHT:4,
        # 同花顺
        CARD_TYPE.FLUSH_STRAIGHT:9,
        # 四条
        CARD_TYPE.FOUR: 13,
        # 葫芦
        CARD_TYPE.FULL_HOUSE:156,
        # 同花
        CARD_TYPE.FLUSH: 32, 
        # 顺子
        CARD_TYPE.STRAIGHT:10,
        # 三条
        CARD_TYPE.THREE:13,
        # 两对
        CARD_TYPE.TWO_PAIR:156,
        # 对子
        CARD_TYPE.PAIR:13,
        # 单牌
        CARD_TYPE.SINGLE:1277
    }
)
# 牌型基础分
SCORE_BASE = {CARD_TYPE.SINGLE:0}
_last_type = None

for _type in list(SCORE_DIST.keys())[::-1][1:]:
    if _last_type is None:
        SCORE_BASE[_type] = SCORE_DIST[_type+1]
    else:
        SCORE_BASE[_type] = SCORE_BASE[_last_type]+SCORE_DIST[_type+1]
    _last_type = _type

def encode_card(card_list:List[str]):
    encode = [0] * 52
    def _card_index(card):
        return COLOR.index(card[0])*len(NUMBER) + NUMBER.index(card[1:])
    for _index in list(map(_card_index, card_list)):
        encode[_index] = 1
    return encode